<template>
  <div class="mod-config">
    <basic-container>
      <div class="boxsty zhiBiao" v-if="showH ==1">
            <div style="border-top: 1px solid #b0bde2">
                <div class="mt10">
                    <div style="float:right">
                       <el-button type="primary" @click="okAll" v-loading.fullscreen.lock="fullscreenLoading">批量同意</el-button>
                       <el-button type="primary" @click="backAll" v-loading.fullscreen.lock="fullscreenLoading2">批量驳回</el-button>
                       <el-button type="primary" @click="fanHu">返回</el-button>
                    </div>
                </div>
            </div>
            <el-table :data="dataList"
                    style="width: 100%;margin-top:20px" height="60vh"
                    ref="tableRef">
                <el-table-column :selectable='checkboxSelect' type="selection" width="55" header-align="center" align="center"></el-table-column>
                <el-table-column type="index" width="80" header-align="center" align="center" label="序号"></el-table-column>
                <el-table-column prop="shouyueName" label="受约人姓名" min-width="120" show-overflow-tooltip header-align="center" align="center"></el-table-column>
                <el-table-column prop="zhibiaoType" label="指标类别" min-width="120" header-align="center" align="center"></el-table-column>
                <el-table-column prop="zhibiaoName" label="指标名称" min-width="120" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="weight" label="权重" min-width="120" header-align="center" align="center"></el-table-column>
                <el-table-column prop="targetValue" label="目标值" min-width="120" header-align="center" align="center"></el-table-column>
                <el-table-column prop="unit" label="单位" min-width="120" header-align="center" align="center"></el-table-column>
                <el-table-column prop="auditStatus" label="状态" min-width="120" header-align="center" align="center">
                    <template slot-scope="scope">
                        <span v-if="scope.row.auditStatus == '0'">待审批</span>
                        <span v-if="scope.row.auditStatus == '2'">通过</span>
                        <span v-if="scope.row.auditStatus == '1'">驳回</span>
                    </template>
                </el-table-column>
            </el-table>
      </div>
      <hetongcjTable v-if="showH ==2" @hetongcjC="hetongcjC" :hetongzhibiaoTable='hetongzhibiaoTable' ></hetongcjTable>
    </basic-container>
  </div>
</template>

<script>

import {getPage, okApi, okAllApi, backApi, backAllApi, getPageChild, okAllChildApi, backAllChildApi} from '@/api/hetongrenwu/hetongyeji/hetongzb'
import {radioTwoList} from '@/api/hetongrenwu/hetonghtxxdjb'
import { validatenull } from "@/util/validate";
import { getMainOrChild } from '@/api/workflow/ht'
import hetongcjTable from "@/views/hetongrenwu/components/hetongcj-table"

export default {
    components:{
        hetongcjTable,
    },
    data(){
        return{
            form:{},
            streamId: Number,
            streamType: '',
            radio:'1',
            radioTwo:"-1",
            dataList:[],
            pageIndex:1,
            pageSize: 10,
            totalPage: 0,
            searchadvanced: true,
            searchheight: '0',
            radioTwoList:radioTwoList,
            showH:1,
            hetongId:Number,
            hetongzhibiaoTable:{
              lastPage:'zbsh',
              showSearch:true,
              pageTitle:'业绩合同',
              showBackBtn:false
            },
            programInterface: '',
            fullscreenLoading:false,
            fullscreenLoading2:false
        }
    },
    watch:{
      radio(value){
        if(value){
          this.getDataList();
        }
      },
      radioTwo(value){
        if(value){
          this.getDataList();
        }
      }
    },
    methods:{
        init(formInfo,
            formInfoDetailed,
            formData,
            GUID,
            wfYwMain,
            wfYwStream,
            dqYwStream,
            dqTask){
            this.programInterface = dqTask.programInterface
            this.form.htId = wfYwMain.ywLyid
            this.streamId = dqYwStream.id
            getMainOrChild(this.streamId).then(res => {
                this.streamType = res.data.data
                this.getDataList()
            })
        },
        getFormData() {
            this.$emit("returnFormData", null);
        },
        //返回到合同创建页面
        fanHu(){
            this.showH=1
        },
        //从合同创建跳转过来执行的方法
        hetongcjC(data){
         //console.log(data);
            if(data){
                this.showH=2
                this.hetongId=data.htId
                this.getDataList();
            }

        },
        searchchangeadvanced() {
            this.searchadvanced = !this.searchadvanced;
            if(this.searchadvanced){
                this.searchheight= 'auto'
            }
        },
        //搜索
        search(){
            this.getDataList()
        },
        //获取指标列表
        getDataList () {
            if(this.streamType == 'child'){
                getPageChild({"htId": this.form.htId, "streamId":this.streamId}).then(response => {
                    this.dataList = response.data.data.records
                    this.totalPage = response.data.data.total
                })
            }else{
                getPage(Object.assign({
                    },this.form)).then(response => {
                    this.dataList = response.data.data.records
                    this.totalPage = response.data.data.total
                })
            }
        },
        // 每页数
        sizeChangeHandle(val) {
            this.pageSize = val
            this.pageIndex = 1
            this.getDataList()
        },
        // 当前页
        currentChangeHandle(val) {
            this.pageIndex = val
            this.getDataList()
        },
        ok(id){
            this.$confirm('是否要通过该指标?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                okApi(id).then(res => {
                    this.$message({
                        type: 'success',
                        message: '提交成功!'
                    });
                    this.getDataList()
                }).catch(() => {
                    this.$message({
                        type: 'error',
                        message: '提交失败!'
                    });
                    this.getDataList()
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提交'
                });
            });
        },
        back(id){
            this.$confirm('是否要驳回该指标?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                backApi(id).then(res => {
                    this.$message({
                        type: 'success',
                        message: '驳回成功!'
                    });
                    this.getDataList()
                }).catch(() => {
                    this.$message({
                        type: 'error',
                        message: '提交失败!'
                    });
                    this.getDataList()
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提交'
                });
            });
        },
        //批量通过
        okAll(){
            const rows = this.$refs.tableRef.selection
            const streamId = this.streamId
            if(this.streamType == 'child'){
                if(rows.length > 0){
                    this.$confirm('是否要通过' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.fullscreenLoading = true;
                        okAllChildApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已通过'
                            });
                            this.fullscreenLoading = false;
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.fullscreenLoading = false;
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标通过!'
                    });
                }
            }else{
                if(rows.length > 0){
                    this.$confirm('是否要通过' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        okAllApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已通过'
                            });
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标通过!'
                    });
                }
            }
        },
        //批量驳回
        backAll(){
            const rows = this.$refs.tableRef.selection
            const streamId = this.streamId
            if(this.streamId == 'child'){
                if(rows.length > 0){
                    this.$confirm('是否要驳回' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.fullscreenLoading2 = true;
                        backAllChildApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已驳回'
                            });
                            this.fullscreenLoading2 = false;
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.fullscreenLoading2 = false;
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标驳回!'
                    });
                }
            }else{
                if(rows.length > 0){
                    this.$confirm('是否要驳回' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        backAllApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已驳回'
                            });
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标驳回!'
                    });
                }
            }
        },
        checkboxSelect (row, rowIndex) {
            if (row.auditStatus == "0") {
                return true
            }else{
                return false
            }
        },
    }
}
</script>

<style>

</style>
